import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Date;
import org.springframework.beans.factory.*;

import org.springframework.beans.factory.xml.*;

import org.springframework.core.io.*;

import org.springframework.jdbc.core.*;

import org.springframework.jdbc.datasource.*;

import org.springframework.jdbc.object.*;

import org.springframework.jdbc.support.*;
import org.springframework.beans.factory.*;

import org.springframework.beans.factory.xml.*;

import org.springframework.core.io.*;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.servlet.*;

import javax.servlet.http.*;
import javax.sql.*;
public class ServletClient extends HttpServlet

{
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			String a = request.getParameter("text1");
			String b = request.getParameter("text2");
			String c = request.getParameter("combo1");
			String d = request.getParameter("combo2");
			out.print(a+b+c+d);
			System.out.println("Waitxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
			try {
				System.out.println("Waitxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
				Resource res = new ClassPathResource("DataCon.xml");
				BeanFactory factory = new XmlBeanFactory(res);
				System.out.println("1");
				DataCon bean1 = (DataCon)factory.getBean("datacon");
				System.out.println("2");
				DataSource ds = bean1.dbcon();
				System.out.println("3");
				if (d.equals("add"))
				{
					System.out.println("4");
					JdbcTemplate jt= new JdbcTemplate(ds);
					System.out.println("555555");
					jt.execute("insert into table1 values('"+a+"','"+b+"') ");
					out.println("Record Added");
				}
				if(d.equals("delete"))

		         {

		            JdbcTemplate   jt = new JdbcTemplate(ds);

		            jt.execute("delete from table1 where name='"+a+"' ");

		            out.println("Record Deleted");

		         }

		         if(d.equals("find"))

		         {

		            List  list1;

		            JdbcTemplate   jt = new  JdbcTemplate(ds);

		            list1=jt.queryForList("select * from table1 where name='"+a+"'");

		            Iterator i=list1.iterator();

		            while(i.hasNext())

		            {

		               Object  ob = i.next();

		               out.println(ob.toString());

		            }

		         }

		         if(d.equals("update"))

		         {

		            if(c.equals("name"))

		            {

		               JdbcTemplate   jt = new  JdbcTemplate(ds);

		               jt.execute("update table1 set table1.place='"+b+"'where table1.name='"+a+"' ");

		           }

		           if(c.equals("place"))

		           {

		               JdbcTemplate   jt = new  JdbcTemplate(ds);

		               jt.execute("update table1 set table1.name='"+a+"'where table1.place='"+b+"' ");

		           }

		           out.println("Record Updated");
		         }
			} catch (Exception e) {
				System.out.println("Exception occurred"+ e.getMessage());
			}
			
	}

//	public void doPost(HttpServletRequest req, HttpServletResponse resp)
//
//	throws ServletException, IOException
//
//	{
//
//		resp.setContentType("text/html");
//
//		PrintWriter out = resp.getWriter();
//
//		String a = req.getParameter("text1");
//
//		try
//
//		{
//
//			System.out.println("Please wait.");
//
//			Resource res = new ClassPathResource("Hello.xml");
//
//			System.out.println("Resource ok");
//
//			BeanFactory factory = new XmlBeanFactory(res);
//
//			System.out.println("BeanFactory ok");
//
//			Hello bean1 = (Hello) factory.getBean("Hello");
//
//			String s = bean1.sayHello(a);
//
//			out.println(s);
//
//		}
//
//		catch (Exception e1)
//
//		{
//			System.out.println("" + e1);
//		}
//
//	}

}